using System;
using System.Configuration;
using System.IO;
using System.Text;
namespace HKB.Common
{
	public class Log
	{
		public static void WriteLog(string msg)
		{
			Log.WriteLog(msg, null);
		}
		public static void WriteLog(string meg, string type)
		{
			if (string.IsNullOrEmpty(type))
			{
				type = "MianWeb";
			}
			string text = ConfigurationManager.AppSettings["LogAddress"].ToString();
			text = text.Remove(text.LastIndexOf('\\') + 1) + type.ToString() + "\\";
			string fileName = string.Concat(new string[]
			{
				text,
				"log",
				System.DateTime.Now.ToString("yyyyMMdd"),
				"\\OperLog",
				System.DateTime.Now.ToString("HH"),
				".txt"
			});
			string path = text + "log" + System.DateTime.Now.ToString("yyyyMMdd");
			System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(path);
			if (!directoryInfo.Exists)
			{
				directoryInfo.Create();
			}
			System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
			if (!fileInfo.Exists)
			{
				System.IO.File.WriteAllText(fileInfo.FullName, "", System.Text.Encoding.UTF8);
			}
			using (System.IO.FileStream fileStream = fileInfo.OpenWrite())
			{
				System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(fileStream);
				streamWriter.BaseStream.Seek(0L, System.IO.SeekOrigin.End);
				streamWriter.WriteLine(meg);
				streamWriter.Flush();
				streamWriter.Close();
			}
		}
	}
}
